package cdu.javaendwork.service.Impl.Shopping;

import cdu.javaendwork.dao.Universal;
import cdu.javaendwork.dao.impl.UniversalImpl;
import cdu.javaendwork.model.sqlModel.Items;
import cdu.javaendwork.service.Interface.Shopping.ItemsService;

import java.math.BigDecimal;
import java.util.List;

public class ItemsServiceImpl implements ItemsService {

    Universal universal = new UniversalImpl();

    @Override
    public boolean insert(int orderid, int goodid, int good_cnt, BigDecimal price) {
        return universal.insert("Items" , orderid , goodid , good_cnt,price) == 1;
    }

    @Override
    public boolean update(int id, int orderid, int goodid, int good_cnt, BigDecimal price) {
        return universal.updateById("Items" , id , orderid,goodid,good_cnt,price) == 1;
    }

    @Override
    public boolean delete(int id) {
        return universal.deleteById("Items" , id) == 1;
    }

    @Override
    public Items findSameItems(int goodid,int orderid) {
        List<Items> list = universal.filter("Items","goodid = " + goodid + " && orderid="+orderid);
        if(!list.isEmpty())
        {
            Items items = list.get(0);
            return items;
        }
        return null;
    }

    @Override
    public Items findById(int id) {
        return universal.getById("Items" , id);
    }

    @Override
    public List<Items> filterByOrderIdLimit(int orderid, int pageIndex, int pageSize) {
        return universal.filterLimit("Items" , "orderid="+orderid , pageIndex , pageSize);
    }
}
